package com.boge.ai;

import okhttp3.*;

import java.util.concurrent.TimeUnit;

public class ChatGPTDemo {
    public static void main(String[] args) throws Exception {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        //RequestBody body = RequestBody.create(mediaType, "{\n  \"messages\": [\n    {\n      \"content\": \"You are a helpful assistant\",\n      \"role\": \"system\"\n    },\n    {\n      \"content\": \"你好啊，你能介绍下中国吗?>\",\n      \"role\": \"user\"\n    }\n  ],\n  \"model\": \"gpt-4o\"}");
        RequestBody body = RequestBody.create(mediaType, """
                {
                  "messages": [
                    {
                      "content": "You are a helpful assistant",
                      "role": "system"
                    },
                    {
                      "content": "长沙天气晴朗，武汉下雨，北京暴雨。你好啊，长沙今天天气怎么样?",
                      "role": "user"
                    }
                  ],
                  "model": "gpt-4o"
                }
                """);
        Request request = new Request.Builder()
                .url("https://ai-yyds.com/v1/chat/completions")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .addHeader("Authorization", "Bearer sk-UrwVZPGfWFwqXGLRE51c1b4dBeD849CcB71dF8E5579a4a09")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
        response.close();
    }
}
